package tpaagp.scheduleus;

import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;


public class AcceptMeetActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		AlertDialog.Builder a = new AlertDialog.Builder(this);
		a.setMessage(R.string.txtAcceptMeet).setPositiveButton("Accept",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						aceptado();
					}
				});
		a.setNegativeButton("No", 
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						vueltaMenu();
					}


				});
		a.show();
	}
	private void vueltaMenu() {
		// TODO Auto-generated method stub
		Intent i = new Intent(this, OptionsMenu.class);
		try {
			startActivity(i);
		} catch (ActivityNotFoundException e) {
			System.out.println("No he trobat l'activity...");
		}		
	}
	public void aceptado() {
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
		String user = prefs.getString("Name", "user");
		String urlS = prefs.getString("URL", "url");
		String name_meet =  prefs.getString("name_meeting", "defValue");
		String queryString = "crear_meeting.php?user="+user+"&accion=aceptar&name_meet="+name_meet;
		HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet(urlS+queryString);
		try {
			client.execute(request);
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		vueltaMenu();
	}


}